package com.untour.im.server.config;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * netty服务启动初始化
 */
@Component
public class LinkServerInitializer implements CommandLineRunner {
    @Resource
    private LinkServer linkServer;
    @Override
    public void run(String... args) throws Exception {
        //netty 服务端启动的端口不可和Springboot启动类的端口号重复
        linkServer.start();

        //关闭服务器的时候同时关闭Netty服务
        Runtime.getRuntime().addShutdownHook(new Thread(() -> linkServer.destroy()));
    }
}
